package com.xu.sys.utils;

import com.mysql.cj.jdbc.MysqlDataSource;
import org.apache.commons.dbutils.QueryRunner;

import javax.sql.DataSource;

//操作数据库的工具类
public class MyDbutils {
//    定义数据源
    private static MysqlDataSource dataSource;
    static {
        // 完成数据源的初始化操作
        dataSource = new MysqlDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/books?serverTimezone=Asia/Shanghai&characterEncoding=UTF-8");
        dataSource.setUser("root");
        dataSource.setPassword("123456");
    }
    public static QueryRunner getQueryRunner(){
        return new QueryRunner(dataSource);
    }
}
